import { PIC_URL } from './../../../../providers/Config';
import { Component, Injector } from '@angular/core';
import { StorageService } from './../../../../providers/StorageService';
import { NativeService } from './../../../../providers/NativeService';
import { BasePage } from './../../../basePage';
import { nailerService } from './../../../../providers/nailerService';
import { IonicPage, NavController, NavParams, ActionSheetController } from 'ionic-angular';

import { CallNumber } from '@ionic-native/call-number';

/**
 * Generated class for the MyShopPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my-shop',
  templateUrl: 'my-shop.html',
})
export class MyShopPage extends BasePage {

  user_info: any;
  shop_info = [];
  picUrl = PIC_URL
  constructor(injector: Injector, private callNumber: CallNumber, public actionSheetCtrl: ActionSheetController, public nailerservice: nailerService, public storage: StorageService, public nativeService: NativeService) {
    super(injector);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyShopPage');
    this.user_info = this.storage.read('userinfo');
    this.myShopInfoAPI();
  }
  shopinfo() {
    // this.navCtrl.push("ShopCompilePage");
    let modal=this.modalCtrl.create("ShopCompilePage");
    modal.onDidDismiss(data=>{
      this.myShopInfoAPI();
    });
    modal.present();
  }
  dismissCLI() {
    this.navCtrl.pop()
  }
  mangerteacher() {
    this.navCtrl.push("MyMasterPage");
  }
  //跳转到已买款式页面
  boughtNail(){
    this.navCtrl.push("BoughtNailPage")
  }
  
  /*店铺秀*/
  shopshow() {
    this.navCtrl.push("StoreShowPage");
  }
    /**调用手机拨号 */
    callNum(phone) {
      this.callNumber.callNumber(phone, true)
        .then(() => console.log('Launched dialer!'))
        .catch(() => console.log('Error launching dialer'));
    }

  /**获取店铺信息 */
  async myShopInfoAPI() {
    let param = { 'user_id': this.user_info.user_id };
    let result = await this.nailerservice.myShopInfoAPI(param);
    console.log(result);
    
    if (result.code == 1) {
      this.shop_info = result.data;
    } else {
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 3000,
        position: 'top',
      })
      toast.present();
    }
  }
  GoRefund(){
    this.navCtrl.push('RefundPage')
  }
}
